//
//  TMGHomeDataController.m
//  TMGold
//
//  Created by Mac on 2017/12/18.
//  Copyright © 2017年 tangmu. All rights reserved.
//

#import "TMGHomeDataController.h"

@implementation TMGHomeDataController
+ (void)send_fecth_banner_request:(void (^)(NSArray *, NSArray<TMBannerModel *> *, STError *))handle{

    NSMutableDictionary * dic = [NSMutableDictionary new];
    NSString * url = [NSString stringWithFormat:@"%@%@",service_header,@"/gold/public/api/home/getAds"];
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 
                                                 NSArray * datas = responseObject[@"data"];
                                                 NSMutableArray * array = [NSMutableArray new];
                                                 NSMutableArray * urls = [NSMutableArray new];
                                                 for (NSDictionary * dataDic in datas) {
                                                     TMBannerModel * model = [TMBannerModel mj_objectWithKeyValues:dataDic];
                                                     [array addObject:model];
                                                     [urls addObject:model.ad_url];
                                                 }
                                                 if (handle) {
                                                     handle(urls,array,nil);
                                                 }
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 if (handle) {
                                                     handle(nil,nil,error);
                                                 }
                                             }];
}

+ (void)send_fecth_products_request:(void (^)(NSArray<TMHomeCellModel *> *, STError *))handle{
    NSMutableDictionary * dic = [NSMutableDictionary new];
    NSString * url = [NSString stringWithFormat:@"%@%@",service_header,@"/gold/public/api/home/getHomeGoods"];
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 
                                                 NSArray * datas = responseObject[@"data"];
                                                 NSMutableArray * array = [NSMutableArray new];
                                                 for (NSDictionary * dataDic in datas) {
                                                     TMHomeCellModel * model = [TMHomeCellModel mj_objectWithKeyValues:dataDic];
                                                     [array addObject:model];
                                                 }
                                                 if (handle) {
                                                     handle(array,nil);
                                                 }
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 if (handle) {
                                                     handle(nil,error);
                                                 }
                                             }];
}
@end
